import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-07-10
 * Time: 18:44
 */
public class test3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int sum = 0;
            int p = 0;
            int q = 1;
            int ret = Integer.MAX_VALUE;
            while(sum<=n){
                sum = p + q;
                p = q;
                q = sum;
                ret = Math.min(ret,Math.abs(n-sum));
            }
            ret = Math.min(ret,sum-n);
            System.out.println(ret);
        }
    }
}
